package com.company;

import java.util.Arrays;

public class Yuekao9 {
    public static void main(String[] args) {
        int[][] a = {{100, 2, 3}, {4, 5, 6}, {17, 8, 9}};
        int sum1, sum2;
        sum1 = sum2 = 0;
        int m = 0;
        for (int i = 0; i < a.length; i++) {
            for (int j = 0; j < a.length; j++) {
                System.out.print(a[i][j] + "\t");
            }
            System.out.println();
        }
        for (int k = 0; k < a.length; k++) {
            sum1 += a[k][k];
        }
        for (int l = 2; l >= 0; l--) {
            //a[2][0]+a[1][1]+a[0][2]
            sum2 += a[l][m];
            m++;
        }
        System.out.println("对角线和分别为：" + sum1 + "和" + sum2);
        //求一个3*3矩阵对角线元素之和
    }
}
